package com.icode.core.dto.manager;

import com.icode.core.model.manage.Contacts;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-7-14
 * Time: 上午11:57
 * To change this template use File | Settings | File Templates.
 */
public class ContactsDTO {

    private String guid;
    private String cusName;
    private String area;
    private String gender;
    private String phone;
    private String product;
    private String price;
    private String paid;  //已付金额
    private String remainder; //剩余金额
    private String week;

    public ContactsDTO() {
    }

    public ContactsDTO(String guid, String cusName, String area, String gender, String phone, String product, String price, String paid, String remainder, String week) {
        this.guid = guid;
        this.cusName = cusName;
        this.area = area;
        this.gender = gender;
        this.phone = phone;
        this.product = product;
        this.price = price;
        this.paid = paid;
        this.remainder = remainder;
        this.week = week;
    }

    public static ContactsDTO toDTO(Contacts contacts) {
        return new ContactsDTO(contacts.guid(), contacts.cusName(), contacts.area(), contacts.gender(), contacts.phone(), contacts.product(), contacts.price(), contacts.paid(), contacts.remainder(), contacts.week());
    }

    public static List<ContactsDTO> toDTOs(List<Contacts> contactses) {
        List<ContactsDTO> contactsDTOs = new ArrayList<>();
        for (Contacts c : contactses) {
            contactsDTOs.add(toDTO(c));
        }
        return contactsDTOs;
    }

    public static Contacts toContacts(ContactsDTO contactsDTO) {
        int remainder = isNumber(contactsDTO.getPrice()) - isNumber(contactsDTO.getPaid());
        return new Contacts(contactsDTO.getCusName(), contactsDTO.getArea(), contactsDTO.getGender(), contactsDTO.getPhone(), contactsDTO.getProduct(), contactsDTO.getPrice(), contactsDTO.getPaid(), String.valueOf(remainder), contactsDTO.getWeek());
    }

    public static int isNumber(String number) {
        String num = number.replaceAll(",", "");
        if(num.equals("")){
            num="0";
        }
        return Integer.parseInt(num);
    }


    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getCusName() {
        return cusName;
    }

    public void setCusName(String cusName) {
        this.cusName = cusName;
    }

    public String getArea() {
        return area;
    }

    public String getPaid() {
        return paid;
    }

    public void setPaid(String paid) {
        this.paid = paid;
    }

    public String getRemainder() {
        return remainder;
    }

    public void setRemainder(String remainder) {
        this.remainder = remainder;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getWeek() {
        return week;
    }

    public void setWeek(String week) {
        this.week = week;
    }
}
